package com.gable.report.controller;

import com.gable.report.common.util.ReturnResultUtil;
import com.gable.report.model.ChartsAreaQuery;
import com.gable.report.model.User;
import com.gable.report.service.ChartsForAreaCostService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

import static com.gable.report.util.ChartsUtil.userRegionMap;

/**
 * 区报表医疗机构绩效
 */
@Controller
@RequestMapping("charts/area/cost")
public class ChartsForAreaCostController {

    private final Log logger = LogFactory.getLog(this.getClass());

    @Resource
    HttpServletRequest request;

    @Autowired
    ChartsForAreaCostService chartsForAreaCostService;


    @RequestMapping("/hospital-page")
    public String pageHospital(){
        return "charts/area/cost-hospital";
    }

    @RequestMapping("/type-page")
    public String pageType(){
        return "charts/area/cost-type";
    }

    @RequestMapping("/model-page")
    public String pageModel(){
        return "charts/area/cost-model";
    }

    /**
     * 区报表区间条件查询
     * @return
     */
    @RequestMapping(value="/interval",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryInterval(HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        //1474861040955131L 为默认区间，查询默认区间值 收支比：10 ~ 15
        Integer type = 2;   //收支比
        Map<String,Object> paramMap = new HashMap<String,Object>();
        paramMap.put("id",userRegionMap.get(user.getId()));
        paramMap.put("type",type);
        return chartsForAreaCostService.queryInterval(paramMap);
    }
    /**
     * @Description: 绩效概况
     * @param chartsAreaQuery
     * @return
     */
    @RequestMapping(value="/overview-hospital",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryOverviewHospital(ChartsAreaQuery chartsAreaQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return chartsForAreaCostService.queryOverview(user,chartsAreaQuery);
    }

    /**
     * 医院绩效报表
     * @param chartsAreaQuery
     * @return
     */
    @RequestMapping(value="/hospital",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryHospitals(ChartsAreaQuery chartsAreaQuery){
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return chartsForAreaCostService.queryHospitals(user,chartsAreaQuery);
    }


    /**
     * 设备类型绩效报表
     * @param chartsAreaQuery
     * @return
     */
    @RequestMapping(value="/type",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryDeviceTypes(ChartsAreaQuery chartsAreaQuery){
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return chartsForAreaCostService.queryDeviceTypes(user,chartsAreaQuery);
    }

    /**
     * 品牌绩效报表
     * @param chartsAreaQuery
     * @return
     */
    @RequestMapping(value="/brand",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryBrand(ChartsAreaQuery chartsAreaQuery){
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return chartsForAreaCostService.queryBrand(user,chartsAreaQuery);
    }

    /**
     * @Description:  设备型号
     * @param chartsAreaQuery
     * @return
     */
    @RequestMapping(value="/model",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryDeviceModels(ChartsAreaQuery chartsAreaQuery){
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return chartsForAreaCostService.queryDeviceModels(user,chartsAreaQuery);
    }

    /**
     * @Description:  设备绩效
     * @param chartsAreaQuery
     * @return
     */
    @RequestMapping(value="/assets",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryAssets(ChartsAreaQuery chartsAreaQuery){
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return chartsForAreaCostService.queryAssets(user,chartsAreaQuery);
    }

    /**
     * @Description: 月份数据
     * @param chartsAreaQuery
     * @return
     */
    @RequestMapping(value="/month-trend",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryForMonth(ChartsAreaQuery chartsAreaQuery){
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return chartsForAreaCostService.queryForMonth(user,chartsAreaQuery);
    }




}
